package com.aice.chinamapview.slice;

import com.aice.chinamapview.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice implements Component.ClickedListener {
    private Button btn_normal, btn_refresh;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        initView();
    }

    private void initView() {
        btn_normal = (Button) findComponentById(ResourceTable.Id_btn_normal);
        btn_refresh = (Button) findComponentById(ResourceTable.Id_btn_refresh);
        btn_normal.setClickedListener(this::onClick);
        btn_refresh.setClickedListener(this::onClick);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn_normal:
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getAbilityPackageContext().getBundleName())
                        .withAbilityName("com.aice.chinamapview.NarmalAbility")
                        .build();
                intent.setOperation(operation);
                startAbility(intent);
                break;
            case ResourceTable.Id_btn_refresh:
                Intent swipintent = new Intent();
                Operation swipoperation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getAbilityPackageContext().getBundleName())
                        .withAbilityName("com.aice.chinamapview.SwipRefreshAppbarActivity")
                        .build();
                swipintent.setOperation(swipoperation);
                startAbility(swipintent);
                break;
        }
    }

    @Override
    protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {
        super.onAbilityResult(requestCode, resultCode, resultData);
        System.out.println("requestCode: " + requestCode + "resultCode:" + resultCode);
    }
}
